package com.ruoyi.TestControls.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.TestControls.domain.TestControls;
import com.ruoyi.TestControls.service.ITestControlsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试控件Controller
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/TestControls/TestControls")
public class TestControlsController extends BaseController
{
    @Autowired
    private ITestControlsService testControlsService;

    /**
     * 查询测试控件列表
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestControls testControls)
    {
        startPage();
        List<TestControls> list = testControlsService.selectTestControlsList(testControls);
        return getDataTable(list);
    }

    /**
     * 导出测试控件列表
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:export')")
    @Log(title = "测试控件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestControls testControls)
    {
        List<TestControls> list = testControlsService.selectTestControlsList(testControls);
        ExcelUtil<TestControls> util = new ExcelUtil<TestControls>(TestControls.class);
        util.exportExcel(response, list, "测试控件数据");
    }

    /**
     * 获取测试控件详细信息
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(testControlsService.selectTestControlsById(id));
    }

    /**
     * 新增测试控件
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:add')")
    @Log(title = "测试控件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestControls testControls)
    {
        return toAjax(testControlsService.insertTestControls(testControls));
    }

    /**
     * 修改测试控件
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:edit')")
    @Log(title = "测试控件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestControls testControls)
    {
        return toAjax(testControlsService.updateTestControls(testControls));
    }

    /**
     * 删除测试控件
     */
    @PreAuthorize("@ss.hasPermi('TestControls:TestControls:remove')")
    @Log(title = "测试控件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testControlsService.deleteTestControlsByIds(ids));
    }
}
